package top.canyue.eca_manager.provider;

import java.util.List;
import java.util.Map;

public class ConferenceDetailProvider {

    public String persistentCache(String conferenceId, String userId, Map<String, Integer> data) {
        StringBuilder sql = new StringBuilder();
        sql.append("UPDATE conferencedetail SET ");
        if (data.get("sad") != null) {
            sql.append("sad=").append(data.get("sad")).append(",");
        }
        if (data.get("angry") != null) {
            sql.append("angry=").append(data.get("angry")).append(",");
        }
        if (data.get("surprise") != null) {
            sql.append("surprise=").append(data.get("surprise")).append(",");
        }
        if (data.get("fear") != null) {
            sql.append("fear=").append(data.get("fear")).append(",");
        }
        if (data.get("happy") != null) {
            sql.append("happy=").append(data.get("happy")).append(",");
        }
        if (data.get("disgust") != null) {
            sql.append("disgust=").append(data.get("disgust")).append(",");
        }
        if (data.get("neutral") != null) {
            sql.append("neutral=").append(data.get("neutral")).append(",");
        }
        sql.append("updateTime=").append("NOW() ");
        sql.append("WHERE conference_id = #{conferenceId} AND user_id = #{userId} ");
        return sql.toString();
    }

    public String leaveConferenceByAllUser(List<String> userIdList, String conferenceId) {
        StringBuilder sql = new StringBuilder();
        sql.append("UPDATE conferencedetail SET isDelete = 1, id = MD5(UUID()) ");
        sql.append("WHERE user_id IN (");
        for (int i = 0; i < userIdList.size(); i++) {
            sql.append("'").append(userIdList.get(i)).append("'");
            if (i < userIdList.size() - 1) {
                sql.append(",");
            }
        }
        sql.append(") AND conference_id = #{conferenceId} ");
        return sql.toString();
    }
}
